package com.itany.cloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        // 参数一:定义路由id
        // 参数二:定义路由的配置,通过lambda表达式配置
        return routes.route("china_news_route",r -> r.path("/guonei").uri("http://news.baidu.com/guonei")).build();
    }

    @Bean
    public RouteLocator routeLocator2(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        // 参数一:定义路由id
        // 参数二:定义路由的配置,通过lambda表达式配置
        return routes.route("baike_route",r -> r.path("/art").uri("https://baike.baidu.com/art")).build();
    }

}
